﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class OverRideoverLoad : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        //Calculator calculator = new Calculator();
        //calculator.Add(1, 2);

        //Restaurant restaurant = new Restaurant();
        //restaurant.ToFu();

        //ToFu_A toFu_A = new ToFu_A();
        //toFu_A.ToFu();

        //ToFu_B toFu_B = new ToFu_B();
        //toFu_B.ToFu();

        ToFu_A toFu_A = new ToFu_A();
        toFu_A.adda();
    }

    // Update is called once per frame
    void Update()
    {

    }

}
public class Calculator
{
    /// <summary>
    /// 重写
    /// </summary>
    /// <param name="a"></param>
    /// <param name="b"></param>
    public void Add(int a, int b)
    {
        Debug.Log(a + b);
    }
    public void Add(int a, int b, int c)
    {
        Debug.Log(a + b + c);
    }
}

public class Restaurant
{
    //虚方法，允许子类重写
    public virtual void ToFu()
    {
        Debug.Log("纯豆腐脑");
      
    }
    public int a = 1;
    public int b=2;
    public void Add()
    {
        Debug.Log(a + b);
    }
    public void Add(int a, int b)
    {
        Debug.Log(a + b);
    }
}
public class ToFu_A: Restaurant
{
    public int c=4;
    public int d=3;
    ////重写
    //public override void ToFu()
    //{
    //    Debug.Log("咸豆腐脑");
    //}
    public void adda()
    {
        base.Add(c,d);
    }
}
public class ToFu_B : Restaurant
{
    //重写
    public override void ToFu()
    {
        Debug.Log("甜豆腐脑");
    }
}